def file_tree(root, tree_contents)
      set_pwd = nil
      tree_contents.each do |tree_entry|
        if tree_entry.start_with?('pwd:')
          raise 'Already have a pwd selected' if set_pwd
          tree_entry = tree_entry.sub(/^pwd:/, '')
          raise "#{tree_entry} is not a directory entry (must end with /), can't use as pwd" unless tree_entry.end_with?('/')
          set_pwd = true # Set later
        end

        # Avoid a simple mistake
        tree_entry = tree_entry[1..-1] if tree_entry[0] == '/'

        path = File.absolute_path(tree_entry, root)
        set_pwd = path if set_pwd == true

        if tree_entry.end_with?('/')
          FileUtils.mkdir_p(path)
        else
          FileUtils.mkdir_p(File.dirname(path))
          content = if REQUIRABLE_EXTENSIONS[File.extname(path)] == :native_extension
            File.read(SAMPLE_NATIVE_LIB)
          else
            <<-RUBY
              $last_test_tree_file_executed = #{tree_entry.inspect}
            RUBY
          end
          File.write(path, content)
        end
      end

      Dir.chdir(set_pwd || '.')
    end
def file_tree(root, tree_contents)
      set_pwd = nil
      tree_contents.each do |tree_entry|
        if tree_entry.start_with?('pwd:')
          raise 'Already have a pwd selected' if set_pwd
          tree_entry = tree_entry.sub(/^pwd:/, '')
          raise "#{tree_entry} is not a directory entry (must end with /), can't use as pwd" unless tree_entry.end_with?('/')
          set_pwd = true # Set later
        end

        # Avoid a simple mistake
        tree_entry = tree_entry[1..-1] if tree_entry[0] == '/'

        path = File.absolute_path(tree_entry, root)
        set_pwd = path if set_pwd == true

        if tree_entry.end_with?('/')
          FileUtils.mkdir_p(path)
        else
          FileUtils.mkdir_p(File.dirname(path))
          content = if REQUIRABLE_EXTENSIONS[File.extname(path)] == :native_extension
            File.read(SAMPLE_NATIVE_LIB)
          else
            <<-RUBY
              $last_test_tree_file_executed = #{tree_entry.inspect}
            RUBY
          end
          File.write(path, content)
        end
      end

      Dir.chdir(set_pwd || '.')
    end
Creates a tree of directories and files for testing.
 This is meant to be used within `Dir.mktmpdir`
 The tree_content is an array of paths.
 * Each entry can be as deep as needed, intermediary directories will be created.
 * Finish an entry with a / for the last part to also be a directory.
 * Start an entry with "pwd:" and the current working directory will be set there.
 * if a file ends with .rb, it will contain code to set $last_test_tree_file_executed to the entry (without pwd:)